#ifndef ROSTERWIDGET_H
#define ROSTERWINDOW_H
#include <QWidget>

#include "../handlers.h"

struct QContextMenuEvent;
struct QMenu;
struct QAction;
struct QActionGroup;
struct QString;
struct QTreeWidgetItem;

namespace gloox
{
struct RosterItem;
}

class RosterWidget : public QWidget
{
    Q_OBJECT

public:
    enum ItemRoles {ItemRoleAccountHandler=Qt::UserRole+1, ItemRoleContactJid};

    RosterWidget(QWidget * parent = 0, Qt::WindowFlags f = 0);
    ~RosterWidget();
    void retranslateUi();

public slots:
    //! \brief Add new account to the roster.
    void addAccount(int h);

    //! \brief Update account in the roster.
    void updateAccount(int h);

    //! \brief Remove account from the roster.
    void removeAccount(int h);

    void logoutAll();

protected:
    enum TreeItemType {ItemAccout=1, ItemGroup, ItemDefaultGroup, ItemContact};

    QMenu * contactMenu;
    QMenu * accountMenu;
    QActionGroup * statusActionGroup;
    QAction * statusOnlineAction;
    QAction * statusOfflineAction;

    void createActions();
    void createMenus();
    void initAccounts();
    void contextMenuEvent(QContextMenuEvent * e);

protected slots:
    void changeStatus(QAction *);
    void accountOnline(int h);
    void accountOffline(int h);
    void itemDoubleClick(QTreeWidgetItem * item, int column);

    /**
     * Find top QTreeWidget item that corresponds to given account.
     *
     * @param h handle of account
     * @return pointer to QTreeWidgetItem or 0 if there is no one
     */
    QTreeWidgetItem * findAccountTreeItem(int h);

private:
    struct Private;
    Private * d;

};

#endif
